package cn.edu.hunan.pm.service.impl;

import cn.edu.hunan.pm.exception.BusinessException;
import cn.edu.hunan.pm.mapper.UserMapper;
import cn.edu.hunan.pm.pojo.User;
import cn.edu.hunan.pm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String email, String pwd) {
        User user = userMapper.queryUserByEmailAndPwd(email, pwd);
        if(user==null){
            //用户名或者密码错误
            throw new BusinessException(100404,"邮箱或者密码错误!");
        }
        return user;
    }

    @Override
    public void checkEmailExits(String email) {
        User user = userMapper.queryUserByEmail(email);
        if(user!=null){
            throw new BusinessException(100403,"邮箱已经存在");
        }
    }

    @Override
    public void regist(User u) {
        userMapper.insertUser(u.getEmail(),u.getNickName(),u.getPwd());
    }

    @Override
    public List<User> selectAllUser() {
        return null;
    }
}
